package cn.com.inossem.operation;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.Bundle;
import cn.com.inossem.config.WSConfig;
import cn.com.inossem.network.NetworkConnect;
import cn.com.inossem.requestmanager.WooRequestFactory;

import com.foxykeep.datadroid.exception.ConnectionException;
import com.foxykeep.datadroid.exception.CustomRequestException;
import com.foxykeep.datadroid.exception.DataException;
import com.foxykeep.datadroid.requestmanager.Request;
import com.foxykeep.datadroid.service.RequestService.Operation;

public class JuBaoOperation implements Operation {
	public static final String JUBAO_OPERATION_GOSSIPID = "jubao_operation_gossipid";
	public static final String JUBAO_OPERATION_REPORTTYPE = "jubao_operation_reporttype";
	public static final String JUBAO_OPERATION_COMMENT = "jubao_operation_comment";
	public Bundle bundle;

	@Override
	public Bundle execute(Context arg0, Request request)
			throws ConnectionException, DataException, CustomRequestException {

		String gossipID = request.getString(JUBAO_OPERATION_GOSSIPID);
		String reportType = request.getString(JUBAO_OPERATION_REPORTTYPE);
		String comment = request.getString(JUBAO_OPERATION_COMMENT);

		NetworkConnect connection = new NetworkConnect(WSConfig.LOCAL_URL
				+ "gossip/reportGossip");
		connection.setPostText("{\"gossipID\":\"" + gossipID
				+ "\",\"reportType\":\"" + reportType + "\",\"comment\":\""
				+ comment + "\"}");
		System.out.println("{\"gossipID\":\"" + gossipID
				+ "\",\"reportType\":\"" + reportType + "\",\"comment\":\""
				+ comment + "\"}");
		String body = connection.execute();

		System.out.println("JuBaoOperation:" + body);
		bundle = new Bundle();
		try {
			JSONObject jsonObject = new JSONObject(body);
			int errorFlag = jsonObject.getInt("errorFlag");
			bundle.putInt(WooRequestFactory.BUNDLE_EXTRA_UPDATESUCCESS,
					errorFlag);
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return bundle;
	}

}
